package com.ruoyi.web.controller.api.cbs;

import com.ruoyi.cbs.approval.domain.vo.ApprovalReqVO;
import com.ruoyi.cbs.approval.domain.vo.ApprovalResultVO;
import com.ruoyi.cbs.approval.services.ApprovalServices;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审核业务
 *
 * @author rsj
 * @date 2022-04-04
 */
@Slf4j
@Api("审核信息")
@RestController
@RequestMapping("/api/approval")
public class ApiApprovalController extends BaseController {
    @Autowired
    private ApprovalServices approvalServices;


    @ApiOperation("查询用户审核任务列表")
    @GetMapping("/userTask/list")
    public AjaxResult selectUserApprovalList(String targetName, String approvalType, String status) {
        List<ApprovalResultVO> resultList = approvalServices.selectUserApprovalList(targetName, approvalType, status);

        return AjaxResult.success(resultList);
    }

    /**
     * 保存审核结果
     */
    @ApiOperation("保存审核结果")
    @PostMapping("/result/save")
    public AjaxResult audit(@RequestBody ApprovalReqVO approvalReqVO)
    {
        int i = approvalServices.approval(approvalReqVO);
        return i > 0 ? AjaxResult.success("审核成功") : AjaxResult.error("审核失败");
    }

    /**
     * 查询对象审核流程
     *
     * @param targetId
     * @return
     */
    @ApiOperation("查询审核流程")
    @GetMapping("/detail/{targetId}")
    public AjaxResult approvalDetail(@PathVariable String targetId, @RequestParam(value = "targetType", required = true) String targetType) {
        List<ApprovalResultVO> resultList = approvalServices.getApprovalDetail(targetId, targetType);

        return AjaxResult.success(resultList);
    }






}

